package com.zbkj.front.controller.ai;

import com.zbkj.common.model.system.SystemAttachment;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.response.CommonResult;
import com.zbkj.common.token.FrontTokenComponent;
import com.zbkj.service.service.ai.AiProtraitHairstyleGenerateService;
import com.zbkj.service.service.ai.enums.AiPhgConfigEnum;
import com.zbkj.service.service.ai.request.AiHairstyleMaterialsCallbackRequest;
import com.zbkj.service.service.publics.attachment.SystemAttachmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("api/front/ai-phg")
@Api(tags = "ai人像发型合成")
public class AiPortraitHairstyleGenerateController {

    @Autowired
    private FrontTokenComponent tokenComponent;

    @Autowired
    private SystemAttachmentService systemAttachmentService;

    @Autowired
    private AiProtraitHairstyleGenerateService aiProtraitHairstyleGenerateService;

    @ApiOperation(value="ai人像发型合成-用户人像剪裁历史分页列表")
    @GetMapping(value = "/getUserPrunePageList")
    public CommonResult<CommonPage<SystemAttachment>> getUserPrunePageList(@Validated PageParamRequest pageParamRequest) {
        String pid = systemAttachmentService.getConfigPid(AiPhgConfigEnum.ai_attid_pid_prune.name());
        List<SystemAttachment> list = systemAttachmentService.getUserPageList(
                pageParamRequest,
                tokenComponent.getUserIdCrmebException(),
                Integer.valueOf(pid));
        CommonPage<SystemAttachment> systemAttachmentCommonPage = CommonPage.restPage(list);
        return CommonResult.success(systemAttachmentCommonPage);
    }

    @ApiOperation(value="ai人像发型合成-用户合成图历史分页列表")
    @GetMapping(value = "/getUserGeneratePageList")
    public CommonResult<CommonPage<SystemAttachment>> getUserGeneratePageList(@Validated PageParamRequest pageParamRequest) {
        String pid = systemAttachmentService.getConfigPid(AiPhgConfigEnum.ai_attid_pid_hecheng.name());
        List<SystemAttachment> list = systemAttachmentService.getUserPageList(
                pageParamRequest,
                tokenComponent.getUserIdCrmebException(),
                Integer.valueOf(pid));
        CommonPage<SystemAttachment> systemAttachmentCommonPage = CommonPage.restPage(list);
        return CommonResult.success(systemAttachmentCommonPage);
    }

    @ApiOperation(value="ai人像发型合成-发型素材分页列表")
    @GetMapping(value = "/getAiHmPageList")
    public CommonResult<CommonPage<SystemAttachment>> getAiHmPageList(@Validated PageParamRequest pageParamRequest) {
        String pid = systemAttachmentService.getConfigPid(AiPhgConfigEnum.ai_attid_pid_hm.name());
        List<SystemAttachment> list = systemAttachmentService.getList(
                Integer.valueOf(pid),
                null,
                pageParamRequest);
        CommonPage<SystemAttachment> systemAttachmentCommonPage = CommonPage.restPage(list);
        return CommonResult.success(systemAttachmentCommonPage);
    }

    @ApiOperation(value = "ai人像发型合成-第3步-合成")
    @RequestMapping(value = "/step3Generate", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "attidPH", value = "第2步选择的人像attid"),
            @ApiImplicitParam(name = "attidHM", value = "发型素材attid")
    })
    public CommonResult<SystemAttachment> step3Generate(String attidPH,String attidHM){
        return CommonResult.success(aiProtraitHairstyleGenerateService.step3Generate(attidPH,attidHM));
    }

    @ApiOperation(value="ai人像发型合成-第3步-合成之前的验证")
    @GetMapping(value = "/step3GenerateValidate")
    @ApiImplicitParam(name = "attidPH", value = "第2步选择的人像attid")
    public CommonResult<Boolean> step3GenerateValidate(String attidPH) {
        return CommonResult.success(aiProtraitHairstyleGenerateService.step3GenerateValidate(attidPH));
    }

    @ApiOperation(value = "ai人像发型合成-第2步-提取特征回调")
    @RequestMapping(value = "/step2Callback", method = RequestMethod.POST)
    public CommonResult<Boolean> step2Callback(@RequestBody @Validated AiHairstyleMaterialsCallbackRequest imageVo) {
        return CommonResult.success(aiProtraitHairstyleGenerateService.step2Callback(imageVo));
    }

    @ApiOperation(value = "ai人像发型合成-第2步-提取特征")
    @RequestMapping(value = "/step2ExtractFeature", method = RequestMethod.GET)
    @ApiImplicitParam(name = "attid",value = "人像图片attid")
    public CommonResult<Boolean> step2ExtractFeature(Integer attid){
        return CommonResult.success(aiProtraitHairstyleGenerateService.step2ExtractFeature(attid));
    }

    @ApiOperation(value = "ai人像发型合成-第1步-人像剪裁")
    @RequestMapping(value = "/step1Prune", method = RequestMethod.POST)
    public CommonResult<List<SystemAttachment>> step1Prune(@RequestParam(value = "multipart") MultipartFile multipart) {
        return CommonResult.success(aiProtraitHairstyleGenerateService.step1Prune(multipart));
    }

}
